class GraphicsController < ApplicationController
  # GET /graphics/new
  def new
    @graphic = Graphic.new
  end

  def create
    @graphic = Graphic.new(params[:graphic])
    @graphicable_object = params[:controller_type].singularize.capitalize.constantize.find(params[:graphicable_id])
    @graphic.graphicable = @graphicable_object

    if @graphic.save
      flash[:notice] = 'Graphic was successfully uploaded.'
			if params[:controller_type] == 'categories'
      	redirect_to menu_name_path(@graphic.graphicable.menu_name)
			else
				redirect_to path_for_vail(@graphic.graphicable)
			end
    else
      render :action => "new"
    end
  end

  def destroy
    @graphic = Graphic.find(params[:id])
    @graphic.destroy

    flash[:notice] = 'Graphic was deleted.'
		if @graphic.graphicable_type == 'Category'
    	redirect_to menu_name_path(@graphic.graphicable.menu_name)
		else
			redirect_to path_for_vail(@graphic.graphicable)
		end
  end
end
